﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SCOSub
{
    public partial class UserControl_Staff : UserControl
    {

        public UserControl_Staff()
        {
            InitializeComponent();

        }

        public double[] tc;
       

        private void CFR_radioButton_CheckedChanged(object sender, EventArgs e)
        {
            tcpath_button.Visible = false;
            tcpath_textbox.Visible = false;
            fps_numeric.Visible = true;
            fps_label1.Visible = true;
            mkvmp4outtcbutton.Visible = false;
        }

        private void VFR_radioButton_CheckedChanged(object sender, EventArgs e)
        {
            tcpath_button.Visible = true;
            tcpath_textbox.Visible = true;
            fps_numeric.Visible = false;
            fps_label1.Visible = false;
            mkvmp4outtcbutton.Visible = true;
        }

        private void tcpath_button_Click(object sender, EventArgs e)
        {
            tc_openFileDialog1.Filter = Errors.Export_OpenFileDialogFilter;
            tc_openFileDialog1.ShowDialog();
        }

        private void tc_openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            try
            {
                FileInfo fi = new FileInfo(tc_openFileDialog1.FileName);
            }
            catch
            {
                MessageBox.Show(Errors.Er_Read, Errors.Er_Read_Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            tcpath_textbox.Text = tc_openFileDialog1.FileName;
        }

        private void mkvmp4outtcbutton_Click(object sender, EventArgs e)
        {
            if (openmkvmp4FileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    mkvmp4outtcbutton.Enabled = false;
                    FFMS2.FFMS2VideoProvider ff2 = new SCOSub.FFMS2.FFMS2VideoProvider(openmkvmp4FileDialog.FileName, new SCOSub.FFMS2.FFMS2API.IndexCallbackDelegate(IndexCallback));

                    tc = ff2.TimeCode;
                    tcpath_button.Enabled = false;
                    mkvmp4outtcbutton.Enabled = true;
                    mkvmp4outtcbutton.Text = "timecode已加载";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "提取出错\n" + ex.ToString());
                    mkvmp4outtcbutton.Enabled = true;
                    mkvmp4outtcbutton.Text = "从MKV/MP4提取";
                    tc = null;
                }
            }
        }
        private int IndexCallback(int State, long Current, long Total, System.IntPtr Private)
        {
            mkvmp4outtcbutton.Text = ((int)(Current * 100 / Total)).ToString() + " %";
            Application.DoEvents();
            return 0;
        }





    }
}
